package com.eazy.lkv2.web.listener;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.ServletContextAware;

import com.eazy.lkv2.core.util.Printer;
import com.eazy.lkv2.web.service.system.SystemPermissionService;

@Component
public class StartupListener implements InitializingBean, ServletContextAware {

	@Autowired
	private SystemPermissionService permissionService;
	
	private ServletContext servletContext;
	
	private void loadConfig() {
		  Timer timer = new Timer("loadConfig", true);
	        timer.schedule(new TimerTask() {
	            @Override
	            public void run() {
					Printer.info("站点信息初始化...");
					
					//servletContext.setAttribute("menus", permissionService.findAll());
					
					Printer.info("OK, lkv2.0 加载完了");
	            }
	        }, 3 * 1000);
	}

	@Override
	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
	}
	
	@Override
	public void afterPropertiesSet() throws Exception {
		loadConfig();
	}

}
